package com.zone.service.controller;

import java.util.List;
import java.io.IOException;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zone.common.log.annotation.Log;
import com.zone.common.log.enums.BusinessType;
import com.zone.common.security.annotation.RequiresPermissions;
import com.zone.service.domain.Gun;
import com.zone.service.service.IGunService;
import com.zone.common.core.web.controller.BaseController;
import com.zone.common.core.web.domain.AjaxResult;
import com.zone.common.core.utils.poi.ExcelUtil;
import com.zone.common.core.web.page.TableDataInfo;

/**
 * 枪支管理Controller
 * 
 * @author ningbo
 * @date 2025-11-14
 */
@RestController
@RequestMapping("/gun")
public class GunController extends BaseController
{
    @Autowired
    private IGunService gunService;

    /**
     * 查询枪支管理列表
     */
    @RequiresPermissions("service:gun:list")
    @GetMapping("/list")
    public TableDataInfo list(Gun gun)
    {
        startPage();
        List<Gun> list = gunService.selectGunList(gun);
        return getDataTable(list);
    }

    @RequiresPermissions("service:gun:equip")
    @GetMapping("/equip/list")
    public TableDataInfo equip(Gun gun) {
        startPage();
        List<Gun> list = gunService.selectGunEquipList(gun); // 新增方法
        return getDataTable(list);
    }

    /**
     * 导出枪支管理列表
     */
    @RequiresPermissions("service:gun:export")
    @Log(title = "枪支管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Gun gun)
    {
        List<Gun> list = gunService.selectGunList(gun);
        ExcelUtil<Gun> util = new ExcelUtil<Gun>(Gun.class);
        util.exportExcel(response, list, "枪支管理数据");
    }

    /**
     * 获取枪支管理详细信息
     */
    @RequiresPermissions("service:gun:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(gunService.selectGunById(id));
    }

    /**
     * 新增枪支管理
     */
    @RequiresPermissions("service:gun:add")
    @Log(title = "枪支管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Gun gun)
    {
        return toAjax(gunService.insertGun(gun));
    }

    /**
     * 修改枪支管理
     */
    @RequiresPermissions("service:gun:edit")
    @Log(title = "枪支管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Gun gun)
    {
        return toAjax(gunService.updateGun(gun));
    }

    /**
     * 删除枪支管理
     */
    @RequiresPermissions("service:gun:remove")
    @Log(title = "枪支管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(gunService.deleteGunByIds(ids));
    }
}
